﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Web.Page
{
    public partial class Left : System.Web.UI.Page
    {
        private static XmlDocument menuDoc;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected string BindMenu()
        {
            if (menuDoc == null)
            {
                menuDoc = new XmlDocument();
                menuDoc.Load(Server.MapPath("menu.xml"));
            }

            Menu m = new Menu();
            foreach (System.Xml.XmlNode mbNode in menuDoc.GetElementsByTagName("MenuBar"))
            {
                if (mbNode.Attributes["Enable"].Value == "true")
                {
                    //创建 MenuBar 添加 MenuBar 到 Menu.
                    MenuBar mb = new MenuBar(mbNode.Attributes["Text"].Value);
                    foreach (System.Xml.XmlNode miNode in mbNode.ChildNodes)
                    {
                        if (miNode.Attributes["Enable"].Value == "true")
                        {
                            //if (common.IsPermission(j.Attributes["Permision"].Value, "Readable"))
                            //{
                            MenuItem mi = new MenuItem(miNode.Attributes["Id"].Value, miNode.Attributes["Text"].Value, 
                                miNode.Attributes["ImageUrl"].Value, miNode.Attributes["Url"].Value, 
                                miNode.Attributes["Permision"].Value, true);
                                mb.Add(mi);
                            //}
                        }
                    }
                    if (mb.Count() != 0)
                        m.Add(mb);
                }

            }

            return m.ToString();
        }
    }
}